//
//  UIView+LoadAnimation.m
//  自定义Loading指示器
//
//  Created by zxy on 2018/11/13.
//  Copyright © 2018年 zxy. All rights reserved.
//

#import "UIView+LoadAnimation.h"

@implementation UIView (LoadAnimation)
-(void)LoadAnimationLayerColor:(UIColor *)layerColor animationLayerCount:(NSInteger)layerCount{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.backgroundColor = layerColor.CGColor;
    shapeLayer.bounds = CGRectMake(0, 0, 10, 10);
    shapeLayer.position = CGPointMake(self.bounds.size.width/2, 20);
    shapeLayer.borderColor = [UIColor whiteColor].CGColor;
    shapeLayer.cornerRadius = 5;
    shapeLayer.borderWidth = 0.5;
    shapeLayer.transform = CATransform3DMakeScale(.0, .0, .0);
    
    
    CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    ani.duration = 1;
    ani.repeatCount = HUGE;//无限循环
    ani.fromValue = @1;
    ani.toValue = @0;
    [shapeLayer addAnimation:ani forKey:nil];
    
    //CAReplicatorLayer用于对图层进行复制，包括图层的动画也能复制！可以看着将某一段事务进行重复！
    CAReplicatorLayer *repLayer = [CAReplicatorLayer layer];
    repLayer.frame = self.bounds;
    
    [repLayer addSublayer:shapeLayer];
    repLayer.instanceCount = layerCount; //复制数量
    repLayer.instanceDelay = .1;//颜色
    //沿着z轴旋转360度
    repLayer.instanceTransform = CATransform3DMakeRotation(M_PI*2/layerCount, 0, 0, 1);
    [self.layer addSublayer:repLayer];
}
@end
